package com.irdstudio.efp.riskm.service.impl;

import java.util.List;
import java.util.Objects;

import com.irdstudio.efp.riskm.service.dao.ColltSmsNoticeAppDao;
import com.irdstudio.efp.riskm.service.domain.ColltSmsNoticeApp;
import com.irdstudio.efp.riskm.service.facade.ColltSmsNoticeAppService;
import com.irdstudio.efp.riskm.service.vo.ColltSmsNoticeAppVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;


/**
 * Service Impl: 催收短信通知申请表服务实现
 * @author ligm
 * @date 2019-08-27
 */
@Service("colltSmsNoticeAppService")
public class ColltSmsNoticeAppServiceImpl implements ColltSmsNoticeAppService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(ColltSmsNoticeAppServiceImpl.class);

	@Autowired
	private ColltSmsNoticeAppDao colltSmsNoticeAppDao;

	/**
	 * 新增数据
	 * @param inColltSmsNoticeAppVo
	 * @return
	 */
	public int insertColltSmsNoticeApp(ColltSmsNoticeAppVO inColltSmsNoticeAppVo) {
		logger.debug("当前新增数据为:"+ inColltSmsNoticeAppVo.toString());
		int num = 0;
		try {
			ColltSmsNoticeApp colltSmsNoticeApp = new ColltSmsNoticeApp();
			beanCopy(inColltSmsNoticeAppVo, colltSmsNoticeApp);
			num = colltSmsNoticeAppDao.insertColltSmsNoticeApp(colltSmsNoticeApp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 根据主键删除信息
	 * @param inColltSmsNoticeAppVo
	 * @return
	 */
	public int deleteByPk(ColltSmsNoticeAppVO inColltSmsNoticeAppVo) {
		logger.debug("当前删除数据条件为:"+ inColltSmsNoticeAppVo);
		int num = 0;
		try {
			ColltSmsNoticeApp colltSmsNoticeApp = new ColltSmsNoticeApp();
			beanCopy(inColltSmsNoticeAppVo, colltSmsNoticeApp);
			num = colltSmsNoticeAppDao.deleteByPk(colltSmsNoticeApp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inColltSmsNoticeAppVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 根据主键更新信息
	 * @param inColltSmsNoticeAppVo
	 * @return
	 */
	public int updateByPk(ColltSmsNoticeAppVO inColltSmsNoticeAppVo) {
		logger.debug("当前修改数据为:"+ inColltSmsNoticeAppVo.toString());
		int num = 0;
		try {
			ColltSmsNoticeApp colltSmsNoticeApp = new ColltSmsNoticeApp();
			beanCopy(inColltSmsNoticeAppVo, colltSmsNoticeApp);
			num = colltSmsNoticeAppDao.updateByPk(colltSmsNoticeApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inColltSmsNoticeAppVo +"修改的数据条数为"+ num);
		return num;
	}

	/**
	 * 根据主键查询详情
	 * @param colltSmsNoticeApp
	 * @return
	 */
	public ColltSmsNoticeAppVO queryByPk(ColltSmsNoticeAppVO inColltSmsNoticeAppVo) {

		logger.debug("当前查询参数信息为:"+ inColltSmsNoticeAppVo);
		try {
			ColltSmsNoticeApp queryColltSmsNoticeApp = new ColltSmsNoticeApp();
			beanCopy(inColltSmsNoticeAppVo, queryColltSmsNoticeApp);
			ColltSmsNoticeApp queryRslColltSmsNoticeApp = colltSmsNoticeAppDao.queryByPk(queryColltSmsNoticeApp);
			if (Objects.nonNull(queryRslColltSmsNoticeApp)) {
				ColltSmsNoticeAppVO outColltSmsNoticeAppVo = beanCopy(queryRslColltSmsNoticeApp, new ColltSmsNoticeAppVO());
				logger.debug("当前查询结果为:"+ outColltSmsNoticeAppVo.toString());
				return outColltSmsNoticeAppVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 一级数据权限
	 * @param colltSmsNoticeApp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<ColltSmsNoticeAppVO> queryAllByLevelOne(ColltSmsNoticeAppVO colltSmsNoticeAppVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<ColltSmsNoticeAppVO> list = null;
		try {
			List<ColltSmsNoticeApp> colltSmsNoticeApps = colltSmsNoticeAppDao.queryAllByLevelOneByPage(colltSmsNoticeAppVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:"+ colltSmsNoticeApps.size());
			pageSet(colltSmsNoticeApps, colltSmsNoticeAppVo);
			list = (List<ColltSmsNoticeAppVO>) beansCopy(colltSmsNoticeApps, ColltSmsNoticeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 二级数据权限
	 * @param colltSmsNoticeApp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<ColltSmsNoticeAppVO> queryAllByLevelTwo(ColltSmsNoticeAppVO colltSmsNoticeAppVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<ColltSmsNoticeApp> colltSmsNoticeApps = colltSmsNoticeAppDao.queryAllByLevelTwoByPage(colltSmsNoticeAppVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:"+colltSmsNoticeApps.size());
		List<ColltSmsNoticeAppVO> list = null;
		try {
			pageSet(colltSmsNoticeApps, colltSmsNoticeAppVo);
			list = (List<ColltSmsNoticeAppVO>) beansCopy(colltSmsNoticeApps, ColltSmsNoticeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 三级数据权限
	 * @param colltSmsNoticeApp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<ColltSmsNoticeAppVO> queryAllByLevelThree(ColltSmsNoticeAppVO colltSmsNoticeAppVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<ColltSmsNoticeApp> colltSmsNoticeApps = colltSmsNoticeAppDao.queryAllByLevelThreeByPage(colltSmsNoticeAppVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:"+ colltSmsNoticeApps.size());
		List<ColltSmsNoticeAppVO> list = null;
		try {
			pageSet(colltSmsNoticeApps, colltSmsNoticeAppVo);
			list = (List<ColltSmsNoticeAppVO>) beansCopy(colltSmsNoticeApps, ColltSmsNoticeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * 四级数据权限
	 * @param colltSmsNoticeApp
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<ColltSmsNoticeAppVO> queryAllByLevelFour(ColltSmsNoticeAppVO colltSmsNoticeAppVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<ColltSmsNoticeApp> colltSmsNoticeApps = colltSmsNoticeAppDao.queryAllByLevelFourByPage(colltSmsNoticeAppVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ colltSmsNoticeApps.size());
		List<ColltSmsNoticeAppVO> list = null;
		try {
			pageSet(colltSmsNoticeApps, colltSmsNoticeAppVo);
			list = (List<ColltSmsNoticeAppVO>) beansCopy(colltSmsNoticeApps, ColltSmsNoticeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	/**
	 * TODO:根据催收任务编号查询催收短信通知申请表
	 * @author xiezw
	 * @params  * @param null
	 * @return
	 * @date 2019/9/3 11:28
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	public List<ColltSmsNoticeAppVO> queryByColltTaskNo(ColltSmsNoticeAppVO colltSmsNoticeAppVo) {
		logger.debug("信息的参数信息为:" + colltSmsNoticeAppVo);
		List<ColltSmsNoticeApp> colltSmsNoticeApps= colltSmsNoticeAppDao.queryByColltTaskNo(colltSmsNoticeAppVo);
		logger.debug("信息的结果集数量为:"+ colltSmsNoticeApps.size());
		List<ColltSmsNoticeAppVO> list = null;
		try {
			pageSet(colltSmsNoticeApps, colltSmsNoticeAppVo);
			list = (List<ColltSmsNoticeAppVO>) beansCopy(colltSmsNoticeApps, ColltSmsNoticeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}
}
